package com.qk.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.commom.PageResult;
import com.qk.entity.Role;
import com.qk.mapper.RoleMapper;
import com.qk.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public PageResult<Role> list1(String name, String label, Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<Role> roleList = roleMapper.list1(name,label);
        Page<Role> p = (Page<Role>) roleList;
        return new PageResult<>(p.getTotal(),p.getResult());
    }

    @Override
    public void add(Role role) {
        role.setCreateTime(LocalDateTime.now());
        role.setUpdateTime(LocalDateTime.now());
        roleMapper.insert(role);
    }

    @Override
    public void delete(Integer id) {
        roleMapper.deleteById(id);
    }

    @Override
    public void uptate1(Role role) {
        role.setUpdateTime(LocalDateTime.now());
        roleMapper.update1(role);
    }

    @Override
    public Role getById(Integer id) {
        return roleMapper.getById( id);
    }

    @Override
    public List<Role> getAll() {
        return roleMapper.getAll();
    }
}
